package com.mingmen.canting.personal;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mingmen.canting.R;
import com.mingmen.canting.adapter.DailyAllListAdapter;
import com.mingmen.canting.definerecycleview.SwipeRecyclerView;
import com.mingmen.canting.util.ScalableCardHelper;
import com.mingmen.canting.util.SharePreferenceUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

@SuppressLint("ValidFragment")
public class DailyAllListragment extends Fragment implements DailyAllListAdapter.OnItemClickListener, ScalableCardHelper.OnPageChangeListener {

    @BindView(R.id.recyclerview)
    SwipeRecyclerView mRecyclerview;

    Unbinder unbinder;

    private String mTitle;


    private DailyAllListAdapter mRadioAdapter = null;
    private LinearLayoutManager mLinearLayoutManager;

    private boolean isSelectAll = false;

    private int index = 0;

    public static DailyAllListragment getInstance(String title) {
        DailyAllListragment sf = new DailyAllListragment();
        sf.mTitle = title;
        return sf;
    }


    String token;
    List<String> dataBeanList = new ArrayList<>();

    @BindView(R.id.layout_nodata)
    LinearLayout layout_nodata;
    @BindView(R.id.layout_select_all)
    RelativeLayout layout_select_all;
    @BindView(R.id.btn_writedaily)
    Button btn_writedaily;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fr_dailyall, null);
        TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
        card_title_tv.setText(mTitle);

        unbinder = ButterKnife.bind(this, v);
        token = (String) SharePreferenceUtil.get(getActivity(), "token", "");
        for (int i = 0; i < 10; i++) {
            dataBeanList.add("ITem" + i);
        }

        mLinearLayoutManager = new LinearLayoutManager(getActivity());
//        mRecyclerview.setLayoutManager(mLinearLayoutManager);
        mRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
/*        DividerItemDecoration itemDecorationHeader = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST);
        itemDecorationHeader.setDividerDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.divider_main_bg_height_1));
        mRecyclerview.addItemDecoration(itemDecorationHeader);*/
        mRadioAdapter = new DailyAllListAdapter(getActivity(), dataBeanList);
        mRadioAdapter.setOnItemClickListener(this);

        mRecyclerview.setAdapter(mRadioAdapter);
        ScalableCardHelper cardHelper = new ScalableCardHelper(this);
        cardHelper.attachToRecyclerView(mRecyclerview);
        mRadioAdapter.setDataList(dataBeanList);

        initListener();


        return v;
    }


    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    private void initListener() {


    }

    @OnClick({R.id.btn_writedaily})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_writedaily:

                break;

        }
    }


    @Override
    public void onItemClickListener(View view, int pos, DailyAllListAdapter.ViewName viewName, List<String> myLiveLists) {
        switch (view.getId()) {
            case R.id.btn_zhuijia:


                SharePreferenceUtil.put(getActivity(), "modify", "0");
//                Intent intent = new Intent(getActivity(), ZhenBanXiuGaiActivity.class);
//                intent.putExtra("applyId", myLiveLists.get(pos));
//
//                startActivity(intent);

                break;
            case R.id.view_cb:
            case R.id.layout_check:
            case R.id.check_box:

                break;

            default:

                break;
        }
    }

    @Override
    public void onPageSelected(int position) {

    }
}